package com.manlu.mapper;

import com.manlu.pojo.Category;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

@org.apache.ibatis.annotations.Mapper
public interface CategoryMapper extends Mapper<Category> {
    /**
     * 根据级别查询分类
     *
     * @param level 级别
     * @return
     */
    @Select("select * from category where c_level = #{level} ")
    @Results(id = "",value = {
            @Result(property = "c_id",column = "c_id"),
            @Result(property = "child",column = "c_id",many = @Many(select = "com.manlu.mapper.CategoryMapper.selectCategoryListByCid"))
    })
    List<Category> selectCategoryAllByLevel(@Param("level") String level);


    /**
     * 根据c_id查询
     * @param c_id
     * @return
     */
    @Select("select * from category where c_level = #{c_id} ")
    @Results({
            @Result(property = "c_id",column = "c_id"),
            @Result(property = "count",column = "c_id",one = @One(select = "com.manlu.mapper.InterviewQuestionsMapper.selectCategoryCountByCid"))
    })
    List<Category> selectCategoryListByCid(@Param("c_id") String c_id);

}
